<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 450px;
            height: 300px;
            border: 1px solid gray;
            margin: 100px auto;
            /* border-radius: 10px; */
            padding-top: 25px;
            border-radius: 20px;
        }
        input{
            width: 350px;
            height: 35px;
            margin-left: 50%;
            transform: translateX(-50%);
            border-radius: 10px;
            border: 1px solid gray;
            border-radius: 10px;
            
        }
        button{
            width: 350px;
            height: 35px;
            margin-left: 50%;
            transform: translateX(-50%);
            color: white;
            background-color: rgb(80, 80, 245);
            border: 0;
            border-radius: 10px;
            transition: all 1s;
        }
        button:hover{
            
            background-color: rgb(132, 146, 247);
        }
        .kuang{
            margin-top: 20px;
        }
        p{
            font-size: 13px;
            margin-left: 350px;
            color: rgb(54, 54, 251);
        }
        h2{
            text-align: center;
        }
    </style>
</head>

<body>
    <div class="box">
        <h2>登录</h2>
        <div class="username kuang"><input type="text" placeholder="手机号"></div>
        <div class="password kuang"><input type="password" placeholder="密码"></div>
        <p>忘记密码</p>
        <button>登录</button>

    </div>
</body>

</html>
<script src="./ajax.js"></script>
<script>
    let inps = document.querySelectorAll('input')
    let btn = document.querySelector('button')
    btn.onclick = function () {
        if (inps[0].value && inps[1].value) {
            if (/^1[3-9]\d{9}$/.test(inps[0].value) && /^\d{4}$/.test(inps[1].value)) {
                
                ajax('get', 'https://yantianfeng.com/api/login', { username: inps[0].value, password: inps[1].value }, function (data) {
                    alert(data.msg);
                })
            }
            else{
                alert('手机号/密码格式不正确');
            }
        }
        else {
            alert('用户名和密码不能为空')
        }
    }
</script>